package com.yao.sdk.ui;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.yao.sdk.R;
import com.yao.sdk.core.YaoSDK;
import com.yao.sdk.util.Utils;

/**
 * Created by Administrator on 2015/12/25.
 */
public class UIDialog {

    private UIDialog(){};

    public static UIDialog getInstance() {
        return uiDialog;
    }

    private static UIDialog uiDialog = new UIDialog();



    private class MyDialog extends ProgressDialog {
        Context context;
        private TextView message;
        public MyDialog(Context context) {
            super(context);
            this.context = context;
            //setCustomView();

        }

        /**
         * 设置整个弹出框的视图
         */
        private void setCustomView(){
            View mView = LayoutInflater.from(getContext()).inflate(R.layout.loading_process_dialog_icon, null);
            super.setContentView(mView);
        }

/*
        *//**
         * 设置提示内容文字
         * @param msg
         *//*
        public void setMessage(CharSequence msg){
            message.setText(msg);
        }*/

    }

    MyDialog dialog;

    public void showDialog(Context context, String title, String message){
        if (dialog == null) {
            dialog = new MyDialog(YaoSDK.getApplication());

            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        }

        if (!Utils.isEmpty(title)) {
            dialog.setTitle(title);
        }
        if (Utils.isEmpty(message)) {
            dialog.setMessage("Loading");
        } else {
            dialog.setMessage(message);
        }
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }

    }



    public void cancelDialog() {
        if (dialog != null) {
            dialog.cancel();
        }
    }





}
